package com.shibaobei.activity.controller;

import com.alibaba.fastjson.JSON;
import com.shibaobei.activity.comment.ResponseResult;
import com.shibaobei.activity.model.User;
import com.shibaobei.activity.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2020/4/28 0028.
 */
@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    @ResponseBody
    public JSON login(User user, HttpSession session){

        return userService.login(user,session);
    }
    @RequestMapping("/logout")
    public ModelAndView logout( HttpSession session){
        session.setAttribute("user",null);

        ModelAndView mv = new ModelAndView();
        //使用重定向，此时springmvc.xml配置文件中的视图解析器将会失效
        mv.setViewName("redirect:/");
        return mv;
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    @RequestMapping("/top")
    public String top(){
        return "top";
    }
    @RequestMapping("/left")
    public String left(){
        return "left";
    } @RequestMapping("/right")
    public String right(){
        return "right";
    }
    @RequestMapping("/bottom")
    public String bottom(){
        return "bottom";
    }

}
